<template>
  <div class="album-detail">
    <div class="album-detail_cover">
      <img src="https://p1.music.126.net/FCWD6ibS2JK2B3QAnXuzwQ==/109951167805892385.jpg?param=200y200" alt="" />
      <van-icon name="arrow-left" class="icon" @click="$router.back()"></van-icon>
      <div class="album-detail_cover_content">
        <div class="album_img">
          <img src="https://p1.music.126.net/FCWD6ibS2JK2B3QAnXuzwQ==/109951167805892385.jpg?param=200y200" alt="" />
        </div>
        <div class="album_info">
          <b>{{ albumDetail?.name }}</b>
          <p>歌手: {{ albumDetail?.artists[0].name }}</p>
          <p>发行时间: {{ musicTime(albumDetail?.publishTime) }}</p>
        </div>
      </div>
    </div>
    <div class="album-detail_contain">
      <div class="contain_head">
        <van-icon name="play-circle-o"></van-icon>
        播放全部
        <span style="font-size: 18px; color: var(--font-light-color)">共({{ musicList.length }}首)</span>
      </div>

      <fs-song-item
        :order="index + 1"
        color="var(--font-color)"
        light-color="var(--font-light-color)"
        :is-search="false"
        v-for="(item, index) in musicList"
        :music-detail="item"
        :key="index"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onActivated, onDeactivated } from "vue";
import { useRoute } from "vue-router";
import FsSongItem from "@/components/FsSongItem/FsSongItem.vue";
import type { IAlbumItem } from "@/types/music/albumType";
import type { ISearchSongItem } from "@/types/music/searchSongType";
import { getAlbumDetail } from "@/service/api/musicRequest";

import { musicTime } from "@/utils/timeHandler";

const $route = useRoute();

const albumDetail = ref<IAlbumItem>(),
  musicList = ref<ISearchSongItem[]>([]);

onActivated(() => {
  getAlbumDetail(Number($route.params.id)).then((res) => {
    albumDetail.value = res.album;
    musicList.value = res.songs;
  });
});

onDeactivated(() => {
  musicList.value = [];
});
</script>

<style scoped lang="scss">
.album-detail {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
  z-index: 1003;
  background: var(--box-color);
  color: var(--font-color);

  &_cover {
    position: relative;
    width: 100%;
    height: 45vh;
    .icon {
      position: absolute;
      top: 20px;
      left: 10px;
      color: #fff;
      font-size: 20px;
      z-index: 2;
    }
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      filter: blur(10px);
    }
    &_content {
      position: absolute;
      display: flex;
      align-items: center;
      bottom: 100px;
      left: 20px;
      color: #fff;
      z-index: 2;
      .album_img {
        position: relative;
        width: 100px;
        height: 100px;
        margin-right: 40px;
        img {
          filter: none;
          border-radius: 10px;
        }
        &::after {
          position: absolute;
          content: "";
          top: 50%;
          transform: translateY(-50%);
          right: -20px;
          width: 100%;
          height: 100%;
          border-radius: 50%;
          background-color: #000;
          z-index: -1;
        }
      }
      .album_info {
        display: flex;
        height: 100px;
        flex-direction: column;
        justify-content: space-between;
        b {
          font-size: 20px;
        }
        p {
          margin: 0;
        }
      }
    }
    &:after {
      position: absolute;
      content: "";
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.2);
      z-index: 1;
    }
  }
  &_contain {
    position: absolute;
    width: 100%;
    height: 60vh;
    background-color: var(--box-color);
    top: 40vh;
    border-top-left-radius: 30px;
    border-top-right-radius: 30px;
    z-index: 1;
    .contain_head {
      padding: 20px 20px 10px 20px;
      font-size: 23px;
    }
  }
}
</style>
